package com.app.bimo.module_accounts.mvp.persenter;


import com.alibaba.android.arouter.launcher.ARouter;
import com.app.bimo.commonbusiness.mvp.BasePresenter;
import com.app.bimo.commonbusiness.network.RxObservableUtil;
import com.app.bimo.commonbusiness.util.LoginService;
import com.app.bimo.commonbusiness.util.RouterHub;
import com.app.bimo.library_db.helper.UserHelper;
import com.app.bimo.module_accounts.mvp.constract.PreferenceContract;


public class PreferencePresenter extends BasePresenter<PreferenceContract.Model, PreferenceContract.View> {
    public PreferencePresenter(PreferenceContract.Model model, PreferenceContract.View rootView) {
        super(model, rootView);

    }


    /**
     * 根据男女频道获取偏好数据
     * @param channel
     */
    public void getPreFromModel(int channel) {
        RxObservableUtil.subscribe(mModel.getPre(channel), bindCustomLoadingLifecycle(true), bookStoreDataList -> {
             mRootView.getPreDataNotify(bookStoreDataList);
        });
    }

//    public void setPreFromModel(int channel, String ids) {
//        RxObservableUtil.subscribe(mModel.setPre(channel, ids)
//                , bindCustomLoadingLifecycle(true)
//                , bookStoreDataList -> {
//                    // 处理数据 直接获取到List<JavaBean> carBeans
//                    mRootView.setPreDataNotify();
//                    mRootView.hideDialogLoading();
//                    ((LoginService) ARouter.getInstance().build(RouterHub.ACCOUNT_SERVICE).navigation()).getUserInfo();
//                });
//    }
  public void setPreFromModel(int channel, String ids,int isRegiest) {
        RxObservableUtil.subscribe(mModel.setPre(channel, ids,isRegiest)
                , bindCustomLoadingLifecycle(true)
                , bookStoreDataList -> {
                    // 处理数据 直接获取到List<JavaBean> carBeans
                    mRootView.setPreDataNotify();
                    mRootView.hideDialogLoading();
                    ((LoginService) ARouter.getInstance().build(RouterHub.ACCOUNT_SERVICE).navigation()).getUserInfo();
                });
    }

    /**
     * 获取用户资料保存到db
     */
    public void getUserInfoFromModel() {
        RxObservableUtil.subscribe(mModel.getUserInfo(), bindCustomLifecycle(), bookStoreDataList -> {
            // 处理数据 直接获取到List<JavaBean> carBeans
            if (UserHelper.getsInstance().findUser() != null) {
                UserHelper.getsInstance().removeUser();
            }
            UserHelper.getsInstance().saveUser(bookStoreDataList);
//            mRootView.userInfoNotify(bookStoreDataList);
        });
    }

}
